import {Post} from "amis";

export const autoPaperPageConfig = {
    "type": "page",
    "title": "",
    "className": ".auto-paper",
    "body": [
        {
            "type": "crud",
            "syncLocation": false,
            "name": "crud-table",
            "api": {
                "method": "get",
                "url": "http://localhost:8080/auto_paper/list",
                "messages": {

                },
                adaptor: function (payload) {
                    const { rows, total } = payload.data.papers;
                    var len = rows.length;
                    for (var i = 0; i < len; i++) {
                        rows[i].type = rows[i].type === 1 ? '手动组卷' : (rows[i].type === 2 ? '自动组卷' : '-');
                        rows[i].difficulty = rows[i].difficulty === 1 ? '容易' : (rows[i].difficulty === 2 ? '中等' : rows[i].difficulty === 3 ? '困难' : '-');
                    }
                    return { rows, total };
                },
                "dataType": "form-data"
            },
            "headerToolbar": [
                {
                    "label": "自动组卷",
                    "type": "button",
                    "reload": "crud-table",
                    "actionType": "dialog",
                    "level": "primary",
                    "dialog": {
                        "body": [
                            {
                                "type": "form",
                                "title": "自动组卷",
                                "body": [
                                    {
                                        "label": "试卷名称",
                                        "type": "input-text",
                                        "name": "name",
                                        "id": "u:c992ed37dc53",
                                        "required": true
                                    },
                                    {
                                        "type": "input-number",
                                        "label": "试卷总分",
                                        "name": "sumScore",
                                        "id": "u:28f83000876f",
                                        "keyboard": true,
                                        "step": 1,
                                        "value": "",
                                        "min": 0,
                                        "required": true
                                    },
                                    {
                                        "type": "radios",
                                        "name": "difficulty",
                                        "label": "试卷难度",
                                        "options": [
                                            {
                                                "label": "容易",
                                                "value": 1
                                            },
                                            {
                                                "label": "中等",
                                                "value": 2
                                            },
                                            {
                                                "label": "困难",
                                                "value": 3
                                            }
                                        ],
                                        "id": "u:c60fff8aca2e",
                                        "value": 1,
                                        "selectFirst": false,
                                        "required": true
                                    },
                                    {
                                        "type": "combo",
                                        "label": "选择题目",
                                        "name": "questions",
                                        "multiple": true,
                                        "addable": true,
                                        "removable": true,
                                        "removableMode": "icon",
                                        "addBtn": {
                                            "label": "增加题型",
                                            "icon": "fa fa-plus",
                                            "level": "primary",
                                            "size": "sm",
                                            "id": "u:fafeaa1979c5"
                                        },
                                        "items": [
                                            {
                                                "type": "select",
                                                "name": "type",
                                                "placeholder": "题型",
                                                "source": "${types}",
                                                // "options": [
                                                //     {
                                                //         "label": "选择题",
                                                //         "value": "select"
                                                //     },
                                                //     {
                                                //         "label": "填空题",
                                                //         "value": "blank"
                                                //     },
                                                //     {
                                                //         "label": "主观题",
                                                //         "value": "picture"
                                                //     }
                                                // ],
                                                "id": "u:212d9ae94af0",
                                                "unique": "true",
                                                "multiple": false
                                            },
                                            {
                                                "type": "input-number",
                                                "name": "num",
                                                "placeholder": "题目数量",
                                                "id": "u:8cff41fe4ea6",
                                                "keyboard": true,
                                                "step": 1,
                                                "min": 1
                                            }
                                        ],
                                        "id": "u:7a14ab1bab06",
                                        "strictMode": true,
                                        "syncFields": [
                                        ],
                                        "minLength": 1,
                                        "draggable": false,
                                        "flat": false,
                                        "maxLength": "",
                                        "required": true
                                    }
                                ],
                                "api": {
                                    "url": "http://localhost:8080/auto_paper",
                                    "method": "post",
                                    "requestAdaptor": "",
                                    "adaptor": "",
                                    "messages": {
                                        "success": "自动组卷成功！"
                                    },
                                    "dataType": "json"
                                },
                                "initApi": {
                                    "url": "http://localhost:8080/auto_paper/getQuestionType",
                                    "method": "get",
                                    "requestAdaptor": "",
                                    "adaptor": "console.log(payload.data.questionTypes);\r\nconst label = [];\r\nconst value = [];\r\nconst types = [];\r\nlet len = payload.data.questionTypes.length;\r\nfor (var i = 0; i < len; i++) {\r\n  let q = payload.data.questionTypes[i];\r\n  type = q.type == 'select' ? '选择题' : q.type == 'blank' ? '填空题' : q.type == 'picture' ? '主观题' : null;\r\n  c = q.count;\r\n  l = type + '（题库当前有 ' + c + ' 道题）';\r\n  var o = new Object();\r\n  o.label = l;\r\n  o.value = q.type;\r\n  types.push(o);\r\n}\r\nconsole.log(types);\r\nreturn { types };",
                                },
                                "id": "u:539582fbc651"
                            }
                        ],
                        "size": "lg"
                    },
                    "id": "u:37dcc5692839"
                },
                "bulkActions"
            ],
            "filter": {
                "title": "查询条件",
                "body": [
                    {
                        "type": "input-text",
                        "name": "id",
                        "label": "试卷编号",
                        "id": "u:018b61e8fc2e"
                    },
                    {
                        "type": "select",
                        "label": "题目类型",
                        "name": "type",
                        "options": [
                            {
                                "label": "所有类型",
                                "value": ""
                            },
                            {
                                "label": "手动组卷",
                                "value": "1"
                            },
                            {
                                "label": "自动组卷",
                                "value": "2"
                            }
                        ],
                        "id": "u:b3fe7a62c54c",
                        "multiple": false,
                        "value": "",
                        "placeholder": ""
                    }
                ],
                "id": "u:018b61e8fc2e",
                "submitOnChange": true
            },
            "columns": [
                {
                    "name": "index",
                    "label": "ID",
                    "type": "text",
                    "id": "u:1314ac9e97de"
                },
                {
                    "name": "name",
                    "label": "试卷名称",
                    "type": "text",
                    "id": "u:f29af1538167"
                },
                {
                    "name": "id",
                    "label": "试卷编号",
                    "type": "text",
                    "id": "u:1314ac9e97de"
                },
                {
                    "name": "type",
                    "label": "组卷方式",
                    "type": "text",
                    "placeholder": "-",
                    "id": "u:f29af1538467"
                },
                {
                    "name": "difficulty",
                    "label": "难易度",
                    "type": "text",
                    "id": "u:f29af1538467"
                },
                {
                    "type": "text",
                    "label": "试卷总分",
                    "name": "sumScore",
                    "placeholder": "0",
                    "id": "u:3c0de8bf82b8"
                },
                {
                    "type": "text",
                    "label": "题目数量",
                    "name": "questionNum",
                    "placeholder": "0",
                    "id": "u:a4230eb9c9ab"
                },
                {
                    "type": "date",
                    "label": "创建时间",
                    "name": "createTime",
                    "id": "u:9611fc99d5db"
                },
                {
                    "type": "operation",
                    "label": "查看详情",
                    "buttons": [
                        {
                            "type": "button",
                            "label": "查看",
                            "onEvent": {
                                "click": {
                                    "weight": 0,
                                    "actions": [
                                        {
                                            "actionType": "dialog",
                                            "dialog": {
                                                "type": "dialog",
                                                "title": "试卷详情",
                                                "body": [
                                                    {
                                                        "type": "tpl",
                                                        "tpl": "${name}",
                                                        "wrapperComponent": "h1",
                                                        "inline": true,
                                                        "id": "u:69cfd048dfed",
                                                        "style": {
                                                            "fontWeight": "900",
                                                            "text-align": "center"
                                                        }
                                                    },
                                                    {
                                                        "type": "tpl",
                                                        "tpl": "共 ${questionNum} 道题，试卷总分为 ${sumScore} 分，难度：${difficulty}",
                                                        "inline": true,
                                                        "wrapperComponent": "h3",
                                                        "id": "u:46a41de305f8",
                                                        "style": {
                                                            "text-align": "center"
                                                        }
                                                    },
                                                    {
                                                        "type": "each",
                                                        "name": "questionList",
                                                        "items": [
                                                            {
                                                                "type": "container",
                                                                "id": "u:ef1a40173e72",
                                                                "style": {
                                                                    "position": "static",
                                                                    "display": "block",
                                                                    "overflowY": "auto"
                                                                },
                                                                "isFixedHeight": false,
                                                                "isFixedWidth": false,
                                                                "body": [
                                                                    {
                                                                        "type": "grid",
                                                                        "columns": [
                                                                            {
                                                                                "body": [
                                                                                    {
                                                                                        "type": "tpl",
                                                                                        "tpl": "${titleNo}. (${type=='picture'?'主观题':(${type}=='blank'?'填空题':'选择题')}${difficulty==1?'-容易':(${difficulty}==2?'-中等':(${difficulty}==3?'-困难':''))})",
                                                                                        "wrapperComponent": "h3",
                                                                                        "inline": false,
                                                                                        "id": "u:dc7160b3abc2",
                                                                                        "style": {
                                                                                            "fontWeight": "700"
                                                                                        }
                                                                                    }
                                                                                ],
                                                                                "id": "u:a73ef3f6cd08",
                                                                                "md": "auto"
                                                                            },
                                                                            {
                                                                                "body": [
                                                                                    {
                                                                                        "type": "tpl",
                                                                                        "tpl": "${content}",
                                                                                        "wrapperComponent": "h3",
                                                                                        "inline": false,
                                                                                        "id": "u:f8d1e3aed7e6",
                                                                                        "style": {
                                                                                            "fontWeight": "700"
                                                                                        },
                                                                                        "hiddenOn": "${type=='picture'}"
                                                                                    },
                                                                                    {
                                                                                        "type": "image",
                                                                                        "id": "u:768366a379e6",
                                                                                        "enlargeAble": true,
                                                                                        "src": "${content}",
                                                                                        "imageMode": "thumb",
                                                                                        "thumbRatio": "4:3",
                                                                                        "width": 500,
                                                                                        "height": 200,
                                                                                        "imageCaption": "",
                                                                                        "title": "",
                                                                                        "showToolbar": true,
                                                                                        "imageClassName": "image-amis",
                                                                                        "hiddenOn": "${type!='picture'}"
                                                                                    }
                                                                                ],
                                                                                "id": "u:b45c9d132581",
                                                                                "md": "auto"
                                                                            },
                                                                            {
                                                                                "body": [
                                                                                    {
                                                                                        "type": "tpl",
                                                                                        "tpl": "（<%= data.score %>分）",
                                                                                        "wrapperComponent": "h3",
                                                                                        "inline": false,
                                                                                        "id": "u:b86dae258129",
                                                                                        "style": {
                                                                                            "fontWeight": "700"
                                                                                        }
                                                                                    }
                                                                                ],
                                                                                "id": "u:b3a412bbea8d",
                                                                                "md": "auto"
                                                                            }
                                                                        ],
                                                                        "id": "u:e58f78a64bb7",
                                                                        "style": {
                                                                            "height": "100%",
                                                                            "width": "100%"
                                                                        }
                                                                    }
                                                                ]
                                                            },
                                                            {
                                                                "type": "container",
                                                                "id": "u:acb8e8141eeb",
                                                                "style": {
                                                                    "position": "static",
                                                                    "display": "block",
                                                                    "height": "100px",
                                                                    "overflowY": "auto"
                                                                },
                                                                "isFixedHeight": true,
                                                                "isFixedWidth": false
                                                            }
                                                        ],
                                                        "id": "u:2a4297f801d9",
                                                        "placeholder": "暂无内容"
                                                    }
                                                ],
                                                "showCloseButton": true,
                                                "showErrorMsg": true,
                                                "showLoading": true,
                                                "className": "app-popover",
                                                "id": "u:9acccc563fa2",
                                                "closeOnEsc": true,
                                                "closeOnOutside": true,
                                                "disabled": true,
                                                "actions": [],
                                                "size": "lg"
                                            }
                                        }
                                    ]
                                }
                            },
                            "id": "u:9a47cda3f022",
                            "level": "link",
                            "size": ""
                        }
                    ],
                    "id": "u:56f428cb7220"
                }
            ],
            "bulkActions": [
            ],
            "itemActions": [
            ],
            "features": [
                "create", "filter", "delete", "update"
            ],
            "id": "u:7aa257c901b6",
            "initFetch": true,
            "loadDataOnce": false,
            "perPageAvailable": [
                10
            ],
            "messages": {
            },
            "alwaysShowPagination": true,
            "footerToolbar": [
                {
                    "type": "statistics"
                },
                {
                    "type": "pagination"
                }
            ]
        }
    ],
    "id": "u:8d661f13be56"
}